﻿/*****************************************************************//**
 * @file    FITKAcousticsVTKCommons.h
 * @brief   Graph object tool functions class.

 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-10-28
 *********************************************************************/

#ifndef __FITKACOUSTICSVTKCOMMONS_H__
#define __FITKACOUSTICSVTKCOMMONS_H__

#include "FITKAcousticsVTKGraphAdaptorAPI.h"

#include <QColor>
#include <QPair>

// Test flags
//@{
// Merge the sub-systems' dataset.
#define SUBSYSTEM_MERGE 1
//@}

// Forward declaration
namespace Acoustics
{
    class FITKAcousticsDiscNodeList;
}

// QString to char*
#ifndef QStringToCharA
#define QStringToCharA(str) \
    str.toUtf8().data()
#endif // !QStringToCharA

// Runtime settings key define
//@{
// Main
#define RTS_KEY_VISIBLE_CAD                 "CAD"
#define RTS_KEY_VISIBLE_GEOMETRY            "GeomVisibility"
#define RTS_KEY_VISIBLE_MESH                "MeshVisibility"
#define RTS_KEY_VISIBLE_GRAPH_NODES         "GraphObjectNodesVisibility"
#define RTS_KEY_VISIBLE_UNUSED_NODES        "UnusedNodesVisibility"
#define RTS_KEY_VISIBLE_NODE_LABELS         "NodeLabelsVisibility"
#define RTS_KEY_VISIBLE_SUB_SYSTEMS         "SubSystemVisibility"
#define RTS_KEY_VISIBLE_SEA_FREE_EDGES      "SEAFreeEdgesVisibility"
#define RTS_KEY_VISIBLE_JUNCTIONS           "JunctionsVisibility"
#define RTS_KEY_VISIBLE_JUNCTION_POINTS     "JunctionPointsVisibility"
#define RTS_KEY_VISIBLE_JUNCTION_LINES      "JunctionLinesVisibility"
#define RTS_KEY_VISIBLE_JUNCTION_AREAS      "JunctionAreasVisibility"

// Geometry
#define RTS_KEY_VISIBLE_GEOM_VERTS      "GeomVertsVisibility"
#define RTS_KEY_VISIBLE_GEOM_EDGES      "GeomEdgesVisibility"
#define RTS_KEY_VISIBLE_GEOM_FACES      "GeomFacesVisibility"
#define RTS_KEY_VISIBLE_GEOM_SOLIDS     "GeomSolidsVisibility"
#define RTS_KEY_VISIBLE_GEOM_VECTOR     "GeomVectorsVisibility"

// SEA
#define RTS_KEY_VISIBLE_SEA_SUBSYS                  "SEASubSystemsVisibility"
#define RTS_KEY_VISIBLE_SEA_SUBSYS_BEAM             "SEASubSystemBeamVisibility"
#define RTS_KEY_VISIBLE_SEA_SUBSYS_SHELLS           "SEASubSystemShellsVisibility"
#define RTS_KEY_VISIBLE_SEA_SUBSYS_FLAT_PLATE       "SEASubSystemFlatPlateVisibility"
#define RTS_KEY_VISIBLE_SEA_SUBSYS_S_CUR_PLATE      "SEASubSystemSingleCurPlateVisibility"
#define RTS_KEY_VISIBLE_SEA_SUBSYS_D_CUR_PLATE      "SEASubSystemDoubleCurPlateVisibility"
#define RTS_KEY_VISIBLE_SEA_SUBSYS_CYLINDER_PLATE   "SEASubSystemCylinderPlateVisibility"
#define RTS_KEY_VISIBLE_SEA_SUBSYS_CAVITY           "SEASubSystemCavityVisibility"
#define RTS_KEY_VISIBLE_SEA_SUBSYS_SEMI_INF_FLUID   "SEASubSystemSemiInfiniteFluidVisibility"
#define RTS_KEY_VISIBLE_SEA_JUNC_POINTS             "SEAJunctionPointsVisibility"
#define RTS_KEY_VISIBLE_SEA_JUNC_LINES              "SEAJunctionLinesVisibility"
#define RTS_KEY_VISIBLE_SEA_JUNC_AREAS              "SEAJunctionAreasVisibility"
#define RTS_KEY_SCALE_MODE                          "SEASystemScaleMode"

// FE
#define RTS_KEY_VISIBLE_FE              "FEVisibility"
#define RTS_KEY_VISIBLE_FE_SURFACE      "FESurfaceVisibility"
#define RTS_KEY_VISIBLE_FE_STRUCT       "FEStructVisibility"
#define RTS_KEY_VISIBLE_FE_ACOUSTICS    "FEAcousticsVisibility"
#define RTS_KEY_VISIBLE_FE_JUNC_POINTS  "FEJunctionPointsVisibility"
#define RTS_KEY_VISIBLE_FE_JUNC_LINES   "FEJunctionLinesVisibility"
#define RTS_KEY_VISIBLE_FE_JUNC_AREAS   "FEJunctionAreasVisibility"

//Hybrid
#define RTS_KEY_VISIBLE_HYBRID_JUNC_POINTS  "HybridJunctionPointsVisibility"
#define RTS_KEY_VISIBLE_HYBRID_JUNC_LINES   "HybridJunctionLinesVisibility"
#define RTS_KEY_VISIBLE_HYBRID_JUNC_AREAS   "HybridJunctionAreasVisibility"

//sensor
#define RTS_KEY_VISIBLE_SENSOR   "SensorVisibility"

// Mix
#define RTS_KEY_VISIBLE_MIX_JUNC_POINTS "MixedJunctionPointsVisibility"
#define RTS_KEY_VISIBLE_MIX_JUNC_LINES  "MixedJunctionLinesVisibility"
#define RTS_KEY_VISIBLE_MIX_JUNC_AREAS  "MixedJunctionAreasVisibility"

// Load
#define RTS_KEY_VISIBLE_LOADS           "LoadsVisibility"
#define RTS_KEY_VISIBLE_LOAD_POINTFORCE "LoadPointSourceVisibility"
#define RTS_KEY_VISIBLE_LOAD_POWER      "LoadPowerVisibility"
#define RTS_KEY_VISIBLE_LOAD_CONSTRAINT "LoadConstraintVisibility"
#define RTS_KEY_VISIBLE_LOAD_HVACNoise  "LoadHVACNoiseVisibility"
#define RTS_KEY_VISIBLE_LOAD_MONOPOLE   "LoadMonopoleVisibility"

// Custom Size Ratio
#define RTS_KEY_SIZE_RATIO_POINTS   "SizeRatioPoints"
#define RTS_KEY_SIZE_RATIO_LINES    "SizeRatioLines"
#define RTS_KEY_SIZE_RATIO_SOURCES  "SizeRatioSources"
//@}

//Tool Graph Key
#define Tool_KEY_DIRECTION_DIR    "ToolDirectionDir"
#define Tool_KEY_DIRECTION_POS    "ToolDirectionPOS"

namespace Exchange
{
    /**
     * @brief   Graph object tool functions.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-06-05
     */
    class FITKACOUSTICSGRAPHADAPTORAPI FITKAcousticsVTKCommons
    {
    public:
        /**
         * @brief   The sub-shape type of the graph object.( Shape or mesh type )
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-01
         */
        enum ShapeMeshAbsEnum
        {
            SME_None = -1,
            STA_COMPOUND = 0,
            STA_COMPSOLID,
            STA_SOLID,
            STA_SHELL,
            STA_FACE,
            STA_WIRE,
            STA_EDGE,
            STA_VERTEX,
            STA_SHAPE,
            MT_Node,
            MT_Element
        };

        /**
         * @brief   The pick( select ) mode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-06
         */
        enum ShapePickMode
        {
            PickNone = -1,
            PickVertex = 0,
            PickEdge,
            PickFace,
            PickSolid,
            PickNode,
            PickElement,
            PickAll
        };

        /**
         * @brief   The data type.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-05
         */
        enum AcousticsGraphType
        {
            OtherGraph = -1,
            ModelGraph = 0,
            MeshGraph,
            DiscNodesGraph,
            BeamGraph,
            ShellGraph,
            CavityGraph,
            SemiInfFluid,
            JunctionPoint,
            JunctionLine,
            JunctionArea,
            LoadPointForceGraph,
            LoadPowerGraph,
            LoadConstraintGraph,
            LoadImportGraph,
            LoadExcForMomGraph,
            LoadMonopoleGraph,
            FreeEdgesGraph,
            FEFaceGraph,
            FEStructureBeamGraph,
            FEStructureShellGraph,
            FEAcousticGraph,
            SensorGraph,
        };

        /**
         * @brief   The shape's mesh type.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-06
         */
        enum ShapeType
        {
            ShapeTypeNone = -1,

            // Shape model type.
            ModelVertex = 0,
            ModelEdge,
            ModelFace,
            ModelSolid,

            // Shape mesh type.
            MeshNode,
            MeshElement,

            // Other graph.
            Others
        };

        /**
         * @brief   Save the data information for graph object.
         *          ( This struct is mainly prepared for getting picked information,
         *          if the graph object is not a model, than the struct will only save
         *          the data object id. )
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-05
         */
        struct AcousticsGraphInfo
        {
            // The type of the graph object.
            AcousticsGraphType Type = OtherGraph;

            // The data object id.
            int DataObjId = -1;
        };

    public:
        /**
         * @brief   Get the folder of 3d temp.
         * @return  The folder path
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-06
         */
        static QString GetTempFolder();

        /**
         * @brief   Get the color by the given index from default color list.[static]
         * @param   index: The index of color
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-05
         */
        static QColor GetColorByIndex(int index);

        /**
         * @brief   Get color randomly.[static]
         * @return  The color
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-26
         */
        static QColor GetRandomColor();

        /**
         * @brief   Get the color's rgbf.[static]
         * @param   color: The color
         * @param   rgbf: The RGB float values
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-05
         */
        static void  QColorToDouble3(QColor color, double* rgbf);

        /**
         * @brief   Get the color's rgb.[static]
         * @param   color: The color
         * @param   rgb: The RGB int values.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-05
         */
        static void QColorToInt3(QColor color, int* rgb);

        /**
         * @brief   Get a random value for polygon offset in the given range.
         * @param   minRange: The min range
         * @param   maxRange: The max range( Better to use 'minRange' + 1 )
         * @param   prec: The precision[default]
         * @return  The random polygon offset
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-11
         */
        static double GetRandomPolygonOffset(int minRange, int maxRange, int prec = 6);

        /**
         * @brief   Get the SEA node position by the given SEA node id.[static]
         * @param   seaNodes: The SEA nodes
         * @param   nodeId: The SEA node id
         * @param   pos: The returned node position
         * @return  Whether the node exist
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-08
         */
        static bool GetSEANodePositionById(Acoustics::FITKAcousticsDiscNodeList* seaNodes, int nodeId, double* pos);

        /**
         * @brief   Get the SEA node position by the given SEA node index.[static]
         * @param   seaNodes: The SEA nodes
         * @param   nodeIndex: The SEA node index
         * @param   pos: The returned node position
         * @return  Whether the node exist
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-08
         */
        static bool GetSEANodePositionByIndex(Acoustics::FITKAcousticsDiscNodeList* seaNodes, int nodeIndex, double* pos);

        /**
         * @brief   Clear all the runtime settings about object visibility.[static]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-14
         */
        static void ClearVisibilityRuntimeSettings();
        /**
         * @brief    获取力与力矩载荷颜色
         * @param[i] isEnable                             是否可用的颜色[true:可用状态下的颜色；false：不可用状态下的颜色]
         * @return   QColor                               颜色
         * @author   BaGuijun (baguijun@163.com)
         * @date     2025-01-20
         */
        static QColor getLoadExcForMomColor(bool isEnable);
        /**
         * @brief    获取FE子系统结构颜色
         * @param[i] isEnable                             是否可用的颜色[true:可用状态下的颜色；false：不可用状态下的颜色]
         * @return   QColor                               颜色
         * @author   BaGuijun (baguijun@163.com)
         * @date     2025-01-20
         */
        static QColor getFESubSysStructureColor(bool isEnable);
        /**
         * @brief    获取FE声腔颜色
         * @return   QColor                               颜色
         * @author   BaGuijun (baguijun@163.com)
         * @date     2025-01-20
         */
        static QColor getFESubSysAcousticColor();
        /**
         * @brief    获取全局点大小（计算包含离散点与几何模型）
         * @return   double                        大小
         * @author   BaGuijun (baguijun@163.com)
         * @date     2025-02-11
         */
        static double getGlobalPointSize();
    public:
        // For actors color.
        //@{
        /**
         * @brief   Default color list.[static]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-05
         */
        static QList<QColor> s_colorList;

        /**
         * @brief   The color for geometry vertex.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-11
         */
        static QColor s_geoVertexColor;

        /**
         * @brief   The color for geometry edge.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-11
         */
        static QColor s_geoEdgeColor;

        /**
         * @brief   The color for geometry face.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-11
         */
        static QColor s_geoFaceColor;

        /**
         * @brief   The color for geometry solid.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-01
         */
        static QColor s_geoSolidColor;

        /**
         * @brief   The color for the default and un-assigned mesh face.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-13
         */
        static QColor s_meshFaceColor;

        /**
         * @brief   The color for the highlight mesh face.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-08
         */
        static QColor s_meshFaceHighlightColor;

        /**
         * @brief   The color for SEA nodes glyph.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-10-30
         */
        static QColor s_SEANodesColor;

        /**
         * @brief   The color for SEA free edges.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-14
         */
        static QColor s_SEAFreeEdgesColor;

        /**
         * @brief   The color for sub-system beam.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-04
         */
        static QColor s_SEASubSysBeamColor; 

        /**
         * @brief   The color for sub-system shell.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-04
         */
        static QColor s_SEASubSysShellColor;

        /**
         * @brief   The color for sub-system cavity.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-04
         */
        static QColor s_SEASubSysCavityColor;

        /**
         * @brief   The color for sub-system semi-infinite-fluid.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-06
         */
        static QColor s_SEASubSysSemiInfFluidColor;

        /**
         * @brief   The default color for most of the enabled junctions.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-13
         */
        static QColor s_SEAJunctionEnabledColor;

        /**
         * @brief   The default color for most of the disabled junctions.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-13
         */
        static QColor s_SEAJunctionDisabledColor;

        /**
         * @brief   The default color for most of the enabled junctions.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-14
         */
        static QColor s_FEJunctionEnabledColor;
        /**
         * @brief   The default color for most of the disabled junctions.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-14
         */
        static QColor s_FEJunctionDisabledColor;
        /**
         * @brief  混合连接启用颜色
         * @author BaGuijun (baguijun@163.com)
         * @date   2025-02-08
         */
        static QColor s_HybridJunctionEnabledColor;
        /**
         * @brief  混合连接不可用颜色
         * @author BaGuijun (baguijun@163.com)
         * @date   2025-02-08
         */
        static QColor s_HybridJunctionDisabledColor;
        /**
         * @brief  FE面颜色
         * @author BaGuijun (baguijun@163.com)
         * @date   2024-12-31
         */
        static QColor s_FEFaceColor;
        /**
         * @brief   The default color for the null value post data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-21
         */
        static QColor s_postNullColor;

        /**
         * @brief   The default color for the value above the given range.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-22
         */
        static QColor s_postAboveColor;

        /**
         * @brief   The default color for the value below the given range.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-22
         */
        static QColor s_postBelowColor;
        //@}

        // Size.
        //@{
        /**
         * @brief   The point size for highlighting.[static]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-19
         */
        static double s_highlightPointSize;

        /**
         * @brief   The line width for highlighting.[static]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-19
         */
        static double s_highlightLineWidth;

        /**
         * @brief   The picture glyph size.( Pixel Width, Pixel Height )
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-06
         */
        static QPair<int, int> s_pictureSize;

        /**
         * @brief   The scale factor of the flat shell.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-11
         */
        static double s_flatShellScaleFactor;

        /**
         * @brief   The scale factor of the none-flat shell.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-11
         */
        static double s_curShellScaleFactor;

        /**
         * @brief   The scale factor of the cavity.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-08
         */
        static double s_cavityScaleFactor;
        //@}

        // Properties.
        //@{
        /**
         * @brief   The default transparency for some of the graph object.[static]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-23
         */
        static double s_defaultTransparency;

        /**
         * @brief   The default transparency for some of the geometry and mesh object.[static]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-09
         */
        static double s_defaultModelTransparency;

        /**
         * @brief   The default transparency for the null value post object.[static]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-21
         */
        static double s_defaultNullPostTransparency;
        //@}

        // Advanced.
        //@{
        /**
         * @brief   The default polygon offset of the CAD model.[static]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-19
         */
        static double s_polygonOffsetCAD;
        /**
         * @brief  几何体偏移量
         * @author BaGuijun (baguijun@163.com)
         * @date   2025-02-19
         */
        static double s_polygonOffsetCADSolid;

        /**
         * @brief   The default polygon offset of the beam.[static]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-19
         */
        static double s_polygonOffsetSEABeam;

        /**
         * @brief   The default polygon offset of the shell.[static]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-19
         */
        static double s_polygonOffsetSEAShell;

        /**
         * @brief   The default polygon offset of the cavity.[static]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-19
         */
        static double s_polygonOffsetSEACavity;

        /**
         * @brief   The default polygon offset of the junction.[static]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-19
         */
        static double s_polygonOffsetSEAJunction;
        /**
         * @brief  FE结构渲染偏移量
         * @author BaGuijun (baguijun@163.com)
         * @date   2025-01-20
         */
        static double s_polygonOffsetFEStruct;
        /**
         * @brief  FE声腔渲染偏移量
         * @author BaGuijun (baguijun@163.com)
         * @date   2025-01-20
         */
        static double s_polygonOffsetFECavity;
        /**
         * @brief  FE面渲染偏移量
         * @author BaGuijun (baguijun@163.com)
         * @date   2025-01-20
         */
        static double s_polygonOffsetFEFace;

        /**
         * @brief   The default polygon offset of the top most marks.[static]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-20
         */
        static double s_polygonOffsetTopMarks;
        //@}
    };
}   // namespace Exchange

#endif // __FITKACOUSTICSVTKCOMMONS_H__
